package com.hornsun.client.personalPage.service;

import com.google.common.base.Preconditions;
import com.hornsun.domain.dbo.OrderForm;
import com.hornsun.client.personalPage.dto.MyOrderDetailDTO;
import com.hornsun.repository.OrderFormDetailRepository;
import com.hornsun.repository.OrderFormRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by 编译中... on 2018/3/28.
 */
@Service
public class OrderService {

    @Autowired
    private OrderFormRepository orderFormRepository;

    @Autowired
    private OrderFormDetailRepository orderFormDetailRepository;

    public List<MyOrderDetailDTO> queryOrderDetail(List<OrderForm> list){
        Preconditions.checkNotNull(list);
        List<MyOrderDetailDTO> orderDetailDTOList = new ArrayList<MyOrderDetailDTO>();
        for (OrderForm orderForm:list){
            MyOrderDetailDTO orderDetailDTO = new MyOrderDetailDTO();
            orderDetailDTO.setOrderForm(orderForm);
            orderDetailDTO.setList(orderFormDetailRepository.selectOrderDetail(orderForm.getOrderGuid()));
            orderDetailDTOList.add(orderDetailDTO);
        }
        return orderDetailDTOList;
    }

    public MyOrderDetailDTO queryOrderDetailByOrderGuid(String orderGuid){
        Preconditions.checkNotNull(orderGuid);
        MyOrderDetailDTO orderDetailDTO = new MyOrderDetailDTO();
        orderDetailDTO.setOrderForm(orderFormRepository.getOrderByOrderGuid(orderGuid));
        orderDetailDTO.setList(orderFormDetailRepository.selectOrderDetail(orderGuid));
        return orderDetailDTO;
    }


    /**
     * 获取所有个人订单信息（按下单时间倒序排序）
     * @param openid
     * @return
     */
    public List<OrderForm> queryOrderForm(String openid,int page){
        Preconditions.checkNotNull(openid);
        Preconditions.checkNotNull(page);
        return orderFormRepository.getOrderForm(openid,page);
    }

    /**
     * 按type类型获取订单
     */
    public List<OrderForm> queryOrderFormByType(String openid,int type,int page){
        Preconditions.checkNotNull(openid);
        Preconditions.checkNotNull(type);
        Preconditions.checkNotNull(page);
        return orderFormRepository.getOrderFormByType(openid,type,page);
    }







}
